package org.example.struct.array;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liyishan
 * @date 2024/1/25 10:05
 * @apiNote
 */

public class Test00696CountBinarySubstrings {

    public static void main(String[] args) {
        String s = "00110011";
        System.out.println(countBinarySubstrings(s));
    }

    public static int countBinarySubstrings(String s) {
        List<Integer> counts = new ArrayList<>();
        int pre = 0,n = s.length();
        while(pre<n){
            char c= s.charAt(pre);
            int count = 0;
            while(pre<n && s.charAt(pre)==c){
                ++pre;
                ++count;
            }
            counts.add(count);
        }
        int ans = 0;
        for(int i = 1;i<counts.size();++i){
            ans += Math.min(counts.get(i-1),counts.get(i));
        }
        return ans;
    }
}
